﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml;
using System.Xml.Linq;

namespace BrandonHaynes.Membership
	{
	/// <summary>
	/// A configuration handler for the brandonHaynes/authenticationRoles node of the web.config
	/// </summary>
	public class RoleMapConfigurationHandler : IConfigurationSectionHandler
		{
		#region IConfigurationSectionHandler Members

		public object Create(object parent, object configContext, XmlNode section)
			{
			// Create a lookup mapping role names to an enumeration of applicable factors
			return section.ChildNodes.Cast<XmlNode>()
				.SelectMany(node => node.ChildNodes.Cast<XmlNode>())
				.ToLookup(
					child => child.ParentNode.Attributes["name"].Value,
					child => child.Attributes["name"].Value);
			}

		#endregion
		}
	}
